
/** 
 * 定义一个入口函数,一开始就执行查询信息
 */
$(function(){
	showAttendanceSet();
});

/**
 * 查询
 */
function showAttendanceSet(){
//	alert("666");
	$.ajax({
		url: "/AttendanceSet/showAttendanceSet",
		type: "post",
		dataType: "json",
		success: function(data){
//			alert("请求查询成功，请继续");
			var content="";
			content+='<thead>'
                +'<tr>'
                +'<th style="display:none">ID</th>'
                +'<th>上班时间</th>'
                +'<th>午休开始时间</th>'
                +'<th>午休结束时间</th>'
                +'<th>下班时间</th>'
                +'<th style="width: 100px;">操作</th>'
                +'</tr>'
                +'</thead>'
                +'<tbody>'
                +'<tr class="success">'
                +'<td style="display:none"></td>'
                +'<td>'+data.as_worktime+'</td>'
                +'<td>'+data.as_noonstarttime+'</td>'
                +'<td>'+data.as_noonendtime+'</td>'
                +'<td>'+data.as_getofftime+'</td>'
                +'<td>'
                +"<a href='javascript:showAttendanceSetHtml("+data.as_id+")' class='btn btn-primary btn'>修改</a>"
                +'</td>'
                +'</tr>'
                +'</tbody>';
			
			$("#showInfo").html(content);
			
		},error: function(data) {
			alert("系统错误，请联系管理员");
		}
	});
}	
	
/**
 * 跳转到修改页面
 */
function showAttendanceSetHtml(id){
//	alert(id);
	// 检查当前页面是否弹层，如果有则删除
	if($('#overtimeDivModel') != null && $('#overtimeDivModel') != undefined)
		$('#overtimeDivModel').remove();
	
	var style_ = 'width: 400px;height: 350px;border: 1px solid #5e5e5e;top: 20%;left: 20%;margin-top: -100px;margin-left: -150px;position: absolute;border-radius: 5px;';
	var content="";
	
	content='<div id="overtimeDivModel" style="' + style_ + '">'
		+'<div class="myDiv">'
        +'<div class="row-fluid">'
        +'<form class="form-horizontal" method="post"  action="#" style="padding: 15px;">'
        +'<input type="hidden" name="id" value="" /> <h3>修改考勤设置：</h3>'
        +'<div class="form-group">'
        +'<label class="col-sm-4 control-label" for="officeHours">上班时间:</label>'
        +'<div class="col-sm-7">'
        +'<input type="text" class="form-control" name="officeHours" id="workTime"/>'
        +'</div>'
        +'</div>'
        +'<div class="form-group">'
        +'<label class="col-sm-4 control-label" for="startTime">午休开始时间:</label>' 
        +'<div class="col-sm-7">'
        +'<input type="text" class="form-control" name="startTime" id="noonStartTime"/>'
        +'</div>'
        +'</div>'
        +'<div class="form-group">'
        +'<label class="col-sm-4 control-label" for="overTime">午休结束时间:</label>' 
        +'<div class="col-sm-7">'
        +'<input type="text" class="form-control" name="overTime" id="noonEndTime">'
        +'</div>'
        +'</div>'
        +'<div class="form-group">'
        +'<label class="col-sm-4 control-label" for="closingTime">下班时间:</label>'
        +'<div class="col-sm-7">'
        +'<input type="text" class="form-control" name="closingTime" id="getoffTime" />'
        +'</div>'
        +'</div>'
        +'<div class="row" style="float:right;">'
        +'<div class="col-sm-12">'
        +'<input type="button" class="btn btn-primary btn" value="提交" onclick="modifyAttendanceSet('+id+')"/>'
        +'</div>'
        +'</div>' 
        +'</form>'
        +'<p style="color: red;text-align: center;"></p>'
        +'</div>'
        +'</div>';
	
	$("body").html(content);
	
	lay('#version').html('-v'+ laydate.v);

	//上班时间445
	laydate.render({
		elem: '#workTime' ,//指定元素
		type: 'time',
		format: 'HH:mm:ss'
	});
	//午休开始时间
	laydate.render({
		elem: '#noonStartTime' ,//指定元素
		type: 'time',
		format: 'HH:mm:ss'
	});
	//午休结束时间
	laydate.render({
		elem: '#noonEndTime' ,//指定元素
		type: 'time',
		format: 'HH:mm:ss'
	});
	//下班时间
	laydate.render({
		elem: '#getoffTime' ,//指定元素
		type: 'time',
		format: 'HH:mm:ss'
	});
	
}//展示修改页面结束

//修改方法
function modifyAttendanceSet(id){
//	alert(id);
	//获取input框的信息
	var worktime = $("#workTime").val();
//	alert(worktime);
	var starttime = $("#noonStartTime").val();
//	alert(worktime);
	var endtime = $("#noonEndTime").val();
	
	var getofftime = $("#getoffTime").val();
	
	$.ajax({
		url: "/AttendanceSet/updateSet",
		type: "post",
		data: {
			as_id: id,
			as_worktime: worktime,
			as_noonstarttime: starttime,
			as_noonendtime: endtime,
			as_getofftime: getofftime
		},
		dataType: "json",
		success: function(data){
//			alert("请求修改考勤设置成功，请继续");
			if(data==1){
				alert("修改成功");
				//跳转页面并刷新页面（调用查询方法）
				window.location.href="/attendanceSetting.html";
			}
		}
	});
}//展示修改页面结束



